cmake_minimum_required(VERSION 3.13.4)
set(ProjectName http-client-demo)
project(${ProjectName} C CXX)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -g -Wall")

# Find the library
find_package(Qt5 COMPONENTS
    Gui
    Core
    DBus
    Network
REQUIRED)

find_package(DtkWidget REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(QGSettings REQUIRED gsettings-qt)
pkg_check_modules(Ssl REQUIRED IMPORTED_TARGET libcrypto libssl openssl)

set(qtWebAppSrcs
    # qtwebapp/httpserver
    src/QtWebApp/httpserver/httpglobal.h
    src/QtWebApp/httpserver/httplistener.h
    src/QtWebApp/httpserver/httpconnectionhandler.h
    src/QtWebApp/httpserver/httpconnectionhandlerpool.h
    src/QtWebApp/httpserver/httprequest.h
    src/QtWebApp/httpserver/httpresponse.h
    src/QtWebApp/httpserver/httpcookie.h
    src/QtWebApp/httpserver/httprequesthandler.h
    src/QtWebApp/httpserver/httpsession.h
    src/QtWebApp/httpserver/httpsessionstore.h
    src/QtWebApp/httpserver/staticfilecontroller.h

    src/QtWebApp/httpserver/httpglobal.cpp
    src/QtWebApp/httpserver/httplistener.cpp
    src/QtWebApp/httpserver/httpconnectionhandler.cpp
    src/QtWebApp/httpserver/httpconnectionhandlerpool.cpp
    src/QtWebApp/httpserver/httprequest.cpp
    src/QtWebApp/httpserver/httpresponse.cpp
    src/QtWebApp/httpserver/httpcookie.cpp
    src/QtWebApp/httpserver/httprequesthandler.cpp
    src/QtWebApp/httpserver/httpsession.cpp
    src/QtWebApp/httpserver/httpsessionstore.cpp
    src/QtWebApp/httpserver/staticfilecontroller.cpp

    # qtwebapp/templateengine
    src/QtWebApp/templateengine/templateglobal.h
    src/QtWebApp/templateengine/template.h
    src/QtWebApp/templateengine/templateloader.h
    src/QtWebApp/templateengine/templatecache.h

    src/QtWebApp/templateengine/template.cpp
    src/QtWebApp/templateengine/templateloader.cpp
    src/QtWebApp/templateengine/templatecache.cpp
)

set(HTTP_SRCS
    src/main.cpp
    src/rsahelper/rsahelper.h
    src/rsahelper/rsahelper.cpp
    src/netclientmodel.h
    src/netclientmodel.cpp
    src/netclientjob.h
    src/netclientjob.cpp
    # netlistener
    src/netlistener/netlistenerrequesthander.h
    src/netlistener/netlistenerrequesthander.cpp
    src/netlistener/netlistenerjob.h
    src/netlistener/netlistenerjob.cpp
)

set(qrcSrcs
    resources.qrc
)

add_executable(${ProjectName}
    ${qtWebAppSrcs}
    ${HTTP_SRCS}
    ${qrcSrcs}
)

target_include_directories(${ProjectName} PUBLIC
    ${Qt5Core_INCLUDE_DIRS}
    ${Qt5DBus_INCLUDE_DIRS}
    ${Qt5Network_INCLUDE_DIRS}
    ${DtkWidget_INCLUDE_DIRS}
    ${QGSettings_INCLUDE_DIRS}
    ${Ssl_INCLUDE_DIRS}
)
target_link_libraries(${ProjectName} PRIVATE
    ${Qt5Core_LIBRARIES}
    ${Qt5DBus_LIBRARIES}
    ${Qt5Network_LIBRARIES}
    ${DtkWidget_LIBRARIES}
    ${QGSettings_LIBRARIES}
    ${Ssl_LIBRARIES}
    crypt
)

install(TARGETS ${ProjectName} DESTINATION ${CMAKE_INSTALL_BINDIR})
